$(document).ready(function() {
	log = log4javascript.getDefaultLogger();
	// 构造组件，模型，建立组件模型之间的一对一关系，给组件设置模板元素
	createComponents($("body"));
});

function createComponents(html) {
	$.each(getChildren(html, "component"), function(i) {
		newObject(this);
	});
}
function newObject(html) {
	var comp = $(html).attr("component");
	var dot = comp.lastIndexOf(".");
	var name = comp.substring(dot + 1, comp.length);
	log.debug("comp name:" + name);
	var conv = eval("conversion." + name);
	eval("var result = " + conv + "(html)");
	return result;
}

/**
 * 根据json格式串创建对象，属性c是构造函数名, 属性id是对象名
 * 
 * @param str
 *            json格式串
 * @return 执行构造函数后的对象
 */
function CommonConversion(comp) {
	var str = $(comp).attr("component")
	var attr = "{"
	attr += $(comp).attr("properties");
	var id = $(comp).attr("id");
	var items = "";
	$("[item=" + id + "]", comp).each(function(i) {
		if (items != "") {
			items += ",";
		}
		if ($(this).attr("component")) {
			items += newObject(this);
		} else {
			items += "{" + $(this).attr("properties") + "}";
		}
		log.debug("items:" + items);
	});
	if (items != "") {
		attr += ",items:[" + items + "]";
	}
	attr += "}";
	log.debug(id + "=new " + str + "(" + attr + ")");
	eval(id + "=new " + str + "(" + attr + ")");
	return id;
}